function [position_legend,forecastValue,rNormal,rBuy,rSell,nTrading,r_excess_after_cost,parameters] = testTimeSeries2(price_path,model,risk_free,cost)
    clc
    rNormal = log(price_path(2:end)./price_path(1:end-1));
    day_lag = 3;
    forecastValue = NaN(length(price_path),1);
    
    rBuy = NaN(length(price_path),1);
    rSell = NaN(length(price_path),1);
    buy = 0;
    sell = 0;
    nTrading = 0;
    flag_get_buy_stock = 0;
    flag_get_sell_stock = 0;
    
    hold on
    h1 = plot(price_path);

    if strcmp(model,'AR1')
        model = arima(1,0,0); %model AR(1)
    elseif strcmp(model,'AR1-GARCH')
        model = arima('ARLags',1,'Variance',garch(1,1)); %model AR(1)-GARCH(1,1)
    elseif strcmp(model,'AR1-EGARCH')
        model = arima('ARLags',1,'Variance',egarch(1,1)); %model AR(1)-EGARCH
    end
    rolling = 5;
    for i = rolling:length(price_path) - day_lag
        [fit,VarCov,~,info] = estimate(model,rNormal(i-rolling+1:i-2));

        [forecastValue(i) ~] = forecast(fit,1,'Y0',rNormal(i-1));
        if(forecastValue(i)>=0)
            rBuy(i+day_lag) = log(price_path(i+day_lag)/price_path(i+day_lag-1))- risk_free;
            buy = 1;
            if flag_get_buy_stock == 0
                h7 = plot(i+day_lag,price_path(i+day_lag),'s','MarkerEdgeColor','k',...
                    'MarkerFaceColor','m','MarkerSize',12);
                flag_get_buy_stock = 1;               
                flag_get_sell_stock = 0;
                last_buy_day = i;
            end
            h5 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                     'MarkerFaceColor','r','MarkerSize',6);
        elseif(forecastValue(i)<0)
            rSell(i+day_lag) = log(price_path(i+day_lag)/price_path(i+day_lag-1))- risk_free;
            sell = 1;
            if flag_get_sell_stock == 0 && flag_get_buy_stock == 1 && i-last_buy_day>=3
                h8 = plot(i,price_path(i),'s','MarkerEdgeColor','k',...
                 'MarkerFaceColor','c','MarkerSize',12);
                flag_get_buy_stock = 0;
                flag_get_sell_stock = 1;
            end
            h6 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                    'MarkerFaceColor','g','MarkerSize',6);
        end

        if buy == 1 && sell == 1
            h9 = plot(i,price_path(i),'o','MarkerEdgeColor','k',...
                    'MarkerFaceColor','y','MarkerSize',7);
            nTrading = nTrading + 1;
            buy = 0;
            sell = 0;
        end
    end
    position_legend = [h1 h5 h6 h7 h8 h9];

    r_excess = mean(rBuy(isnan(rBuy)==0)) + mean(rSell(isnan(rSell)==0));
    r_excess_after_cost = r_excess - cost*r_excess;
    
    parameters = info.X;
    standard_error = sqrt(diag(VarCov));
    t_statistic = info.X./standard_error;

% close all
